package org.example.serial;

import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;

public class ProtostuffUtilsTest {

    private final static String FILE_NAME = "person_psf.txt";

    @Test
    public void write() {
        Person person = Person.builder().id(1001L).name("morningcat").address("Nanjing").build();
        byte[] bytes = ProtostuffUtils.serialize(person);
        try {
            FileUtils.writeByteArrayToFile(new File(FILE_NAME), bytes);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void read() {
        try {
            byte[] bytes = FileUtils.readFileToByteArray(new File(FILE_NAME));
            Person person = ProtostuffUtils.deserialize(bytes, Person.class);
            System.out.println(person);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


}
